using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Sustainalytics.Synchronization.Validation.Restore;

namespace Sustainalytics.Synchronization.Validation
{
    public class ProfileRestoreEngine
    {
        private readonly IEnumerable<IProfileRestoreHandler> dataHandlers;

        public ProfileRestoreEngine(IEnumerable<IProfileRestoreHandler> dataHandlers)
        {
            this.dataHandlers = dataHandlers;
        }

        public async Task RestoreAsync(InvalidCompaniesList invalidCompanies)
        {
            var tasks = dataHandlers.Select(dataHandler => dataHandler.ForEachElementsAsync(invalidCompanies)).ToList();

            await Task.WhenAll(tasks).ConfigureAwait(false);
        }
    }
}